package org.myblog.myblogserver.code.controller;

import org.myblog.myblogserver.code.entity.Notice;
import org.myblog.myblogserver.code.service.NoticeService;
import org.myblog.myblogserver.dao.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;

@Api(tags = "Notice")
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    private Result  result= new Result();

    //增加

    @ApiOperation(value = "Notice新增")
    @PostMapping("/insert")
    public boolean add(@RequestBody Notice notice) {
        return noticeService.save(notice);
    }


    //查询所有
    @ApiOperation(value = "Notice查询所有")
    @GetMapping("/selectAll")
    public Result getAll() {
        if(noticeService.list()==null){
            result.client_fail("数据为空",null);
        }
        else{
            result.success("查询成功", noticeService.list());
        }
        return result;
    }


    //删除全部表示数据
    @ApiOperation(value = "Notice删除全部")
    @DeleteMapping("/deleteAll")
    public boolean deleteAll() {
        return noticeService.remove(null);
    }
}